#ifndef WIDGETSCONTAINER_H
#define WIDGETSCONTAINER_H
#include <memory>
#include <QtGui/QImage>
#include <QtWidgets/QtWidgets>



class QTransition;
class QWidgetsContainer : public QGraphicsView
{
	Q_OBJECT
		Q_ENUMS(TRANSITION_MODE)
public:
	enum TRANSITION_MODE
	{

		MODE_TRANSLATE_X_LEFT,
		MODE_TRANSLATE_X_RIGHT,
		MODE_TRANSLATE_Y_UP,
		MODE_TRANSLATE_Y_DOWN,


		MODE_BOX_H_LEFT,

		MODE_ROTATE_Y_CCW,
		MODE_ROTATE_Y_CW,
		MODE_ROTATE_X_CCW,
		MODE_ROTATE_X_CW,



		MODE_SHADE_X,

		MODE_RANDOM,
	};


	QWidgetsContainer(QWidget *parent = 0);
	~QWidgetsContainer();


	QGraphicsProxyWidget *addWidget(QWidget *widget, Qt::WindowFlags wFlags = 0);
	QGraphicsProxyWidget *removeWidget(QWidget *widget, bool destory = true);
	std::map<QWidget*, QGraphicsProxyWidget*> const& getWidgets() const;

	QWidget* getCurrent()const
	{
		return _currentWidget->widget();
	}
public Q_SLOTS:
	void transition(QWidget* targetWidget, float time = 300, TRANSITION_MODE mode = MODE_TRANSLATE_X_LEFT);
	void setCurrent(QWidget* widget);
	void finished();
protected:
	virtual void valueChanged(qreal value);

private:

	QImage renderWidget(QGraphicsProxyWidget* w);

Q_SIGNALS:

protected:
	void resizeEvent(QResizeEvent *) override;
private:
	QGraphicsScene _scene;

	std::map<QWidget*, QGraphicsProxyWidget*> _widgets;
	QTimeLine _timeline;
	QGraphicsProxyWidget* _oldWidget;


	QGraphicsProxyWidget* _currentWidget;
	QGraphicsProxyWidget* _targetWidget;
	TRANSITION_MODE _mode;

	std::unique_ptr<QTransition> _transition;

	template<TRANSITION_MODE MODE>
	friend class QTransitionT;
};

#endif // WIDGETSCONTAINER_H
